
import 'package:flutter/cupertino.dart';
import 'package:flutter_app/utils/log_util.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';

///author: create by SunJH
///时间: 2021/12/21 0021
///邮箱: 965989158@qq.com
///描述: 网页加载控制器
///
class CounterNetLoading extends GetxController{
  InAppWebViewController? webViewController;
  InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
      crossPlatform: InAppWebViewOptions(
        useShouldOverrideUrlLoading: true,
        mediaPlaybackRequiresUserGesture: false,
      ),
      android: AndroidInAppWebViewOptions(
        useHybridComposition: true,
          supportMultipleWindows: true
      ),
      ios: IOSInAppWebViewOptions(
        allowsInlineMediaPlayback: true,
      ));

  @override
  void onInit() {
  }
  initMethod(){
    webViewController?.addJavaScriptHandler(handlerName: "abs", callback: (args){
      LogUtil.logI(args);
      callJs();
      return "this is flutter'params";
    });
    webViewController?.addJavaScriptHandler(handlerName: "callAndroid", callback: (args){
      LogUtil.logI(args);
      return "this is flutter'params";
    });
    webViewController?.addJavaScriptHandler(handlerName: "jsBridgeResultTest", callback: (args){
      LogUtil.logI(args);
      return "jsBridgeResultTest call ";
    });
  }
  callJs(){
    var source = "javascript:dyzt(1)";
    webViewController?.evaluateJavascript(source: source);
  }
}